import { defineStore } from 'pinia'
import { ref } from 'vue'
import type { Consult, ConsultIllness } from '@/types/consult'
import type { ConsultType } from '@/enums'

export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    // 定义问诊模型
    const consult = ref({} as Consult)

    // 设置type
    const setType = (type: ConsultType) => {
      consult.value.type = type
    }

    // 设置极速问诊类型
    const setIllnessType = (type: 0 | 1) => {
      consult.value.illnessType = type
    }

    // 保存科室（具体到二级科室）
    const setDepId = (depId: string) => {
      consult.value.depId = depId
    }

    // 保存图文信息
    const setIllness = (illness: ConsultIllness) => {
      consult.value.illnessDesc = illness.illnessDesc
      consult.value.illnessTime = illness.illnessTime
      consult.value.consultFlag = illness.consultFlag
      consult.value.pictures = illness.pictures
    }

    // 保存患者信息
    const setPatientId = (patientId: string) => {
      consult.value.patientId = patientId
    }

    // 清除
    const clear = () => {
      consult.value = {} as Consult
    }

    return {
      consult,
      setType,
      setIllnessType,
      setDepId,
      setIllness,
      setPatientId,
      clear
    }
  },
  {
    persist: true
  }
)
